package com.clstu.jdbcs;

import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/**
 * jdbc入门案例
 */
public class Jdbc01 {
    public static void main(String[] args) throws SQLException {

        //1.注册驱动
        Driver driver = new Driver();

        //2.得到连接
        String url = "jdbc:mysql://localhost:3306/cl_db01";
        Properties properties = new Properties();
        properties.setProperty("user","root");
        properties.setProperty("password","root");
        Connection connect = driver.connect(url, properties);//得到网络连接,类似数据通路

        //3.执行sql
        String sql = "insert into users values(5,'吴京',50)";
        Statement statement = connect.createStatement();//用于执行sql语句并返回生成的结果对象
        int i = statement.executeUpdate(sql);//执行sql语句,返回受影响的行数
        System.out.println(i>0?"成功~":"失败");

        //4.关闭连接,释放资源
        statement.close();
        connect.close();


    }
}
